$(function(){
	$("#publishBtn").click(publish);
});

function publish() {
	$("#publishModal").modal("hide");

	//获取标题和内容
	var title = $('#recipient-name').val();
	var content = $('#message-text').val();
	//发送异步请求(post)
	$.post(
		CONTEXT_PATH + '/discuss/add',
		{"title":title, "content":content},
		function (data) {
			data = $.parseJSON(data);
			// 在提示框当中显示返回的消息
			$('#hintBody').text(data.msg);
			// 显示提示框
			$("#hintModal").modal("show");
			// 2秒后自动隐藏提示框
			setTimeout(function(){
				$("#hintModal").modal("hide");
				//跳转到刚发布的帖子详情页面
				if (data.code === 0) {
					// window.location.reload();
					window.location.href = CONTEXT_PATH + "/discuss/detail/" + data.postId;
				}
			}, 2000);
		}
	);

}